package com.runner.utility;

import java.util.ArrayList;

import com.runner.observer.Event;
import com.runner.observer.Subject;

/**
 * Schedule events to go off after their timer has expired
 * @author cjohnson
 *
 */
public class TimedEventManager {
	private ArrayList<TimedEvent> events;
	private ArrayList<TimedEvent> removed;

	public TimedEventManager() {
		events = new ArrayList<TimedEvent>();
		removed=new ArrayList<TimedEvent>();
	}

	public void update(float delta) {
		for (TimedEvent event : events) {
			event.update(delta);
			if(event.isDone()){
				removed.add(event);
			}
		}
		events.removeAll(removed);
		removed.clear();
	}
	
	public void reset(){
		events.clear();
		removed.clear();
	}

	public void scheduleEvent(float timer, Event event, Subject subject) {
		events.add(new TimedEvent(timer,0,event,subject));
	}
}
